from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-26 14:11:30.571485
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 26, Apr, 2021
Time: 14:11:35
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.7786
Nobs: 273.000 HQIC: -48.4909
Log likelihood: 3287.88 FPE: 5.41183e-22
AIC: -48.9686 Det(Omega_mle): 3.91498e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.431704 0.121785 3.545 0.000
L1.Burgenland 0.079009 0.060483 1.306 0.191
L1.Kärnten -0.223594 0.053351 -4.191 0.000
L1.Niederösterreich 0.084594 0.129980 0.651 0.515
L1.Oberösterreich 0.225340 0.125067 1.802 0.072
L1.Salzburg 0.265916 0.069029 3.852 0.000
L1.Steiermark 0.114619 0.087791 1.306 0.192
L1.Tirol 0.119306 0.060697 1.966 0.049
L1.Vorarlberg -0.034954 0.055682 -0.628 0.530
L1.Wien -0.052147 0.112954 -0.462 0.644
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.462488 0.141137 3.277 0.001
L1.Burgenland 0.007543 0.070094 0.108 0.914
L1.Kärnten 0.331849 0.061829 5.367 0.000
L1.Niederösterreich 0.099662 0.150634 0.662 0.508
L1.Oberösterreich -0.064251 0.144940 -0.443 0.658
L1.Salzburg 0.219354 0.079997 2.742 0.006
L1.Steiermark 0.095564 0.101742 0.939 0.348
L1.Tirol 0.137655 0.070342 1.957 0.050
L1.Vorarlberg 0.149425 0.064531 2.316 0.021
L1.Wien -0.428792 0.130903 -3.276 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.273230 0.061715 4.427 0.000
L1.Burgenland 0.100374 0.030650 3.275 0.001
L1.Kärnten -0.013404 0.027036 -0.496 0.620
L1.Niederösterreich 0.084263 0.065868 1.279 0.201
L1.Oberösterreich 0.282547 0.063378 4.458 0.000
L1.Salzburg 0.017783 0.034981 0.508 0.611
L1.Steiermark -0.003233 0.044489 -0.073 0.942
L1.Tirol 0.071202 0.030759 2.315 0.021
L1.Vorarlberg 0.075626 0.028217 2.680 0.007
L1.Wien 0.114294 0.057240 1.997 0.046
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.214703 0.059145 3.630 0.000
L1.Burgenland 0.026350 0.029374 0.897 0.370
L1.Kärnten 0.010186 0.025910 0.393 0.694
L1.Niederösterreich 0.056699 0.063125 0.898 0.369
L1.Oberösterreich 0.396623 0.060739 6.530 0.000
L1.Salzburg 0.078423 0.033524 2.339 0.019
L1.Steiermark 0.129616 0.042636 3.040 0.002
L1.Tirol 0.049314 0.029478 1.673 0.094
L1.Vorarlberg 0.081371 0.027042 3.009 0.003
L1.Wien -0.043538 0.054856 -0.794 0.427
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.488848 0.115808 4.221 0.000
L1.Burgenland 0.098473 0.057515 1.712 0.087
L1.Kärnten 0.010525 0.050733 0.207 0.836
L1.Niederösterreich 0.003154 0.123601 0.026 0.980
L1.Oberösterreich 0.124624 0.118929 1.048 0.295
L1.Salzburg 0.055280 0.065641 0.842 0.400
L1.Steiermark 0.067059 0.083483 0.803 0.422
L1.Tirol 0.207724 0.057719 3.599 0.000
L1.Vorarlberg 0.032748 0.052950 0.618 0.536
L1.Wien -0.081300 0.107411 -0.757 0.449
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.206985 0.091575 2.260 0.024
L1.Burgenland -0.013247 0.045480 -0.291 0.771
L1.Kärnten -0.008191 0.040117 -0.204 0.838
L1.Niederösterreich -0.013811 0.097738 -0.141 0.888
L1.Oberösterreich 0.417540 0.094043 4.440 0.000
L1.Salzburg 0.013154 0.051906 0.253 0.800
L1.Steiermark -0.029072 0.066014 -0.440 0.660
L1.Tirol 0.162535 0.045641 3.561 0.000
L1.Vorarlberg 0.057537 0.041870 1.374 0.169
L1.Wien 0.212334 0.084935 2.500 0.012
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.228653 0.111142 2.057 0.040
L1.Burgenland 0.022667 0.055198 0.411 0.681
L1.Kärnten -0.069427 0.048689 -1.426 0.154
L1.Niederösterreich -0.065463 0.118621 -0.552 0.581
L1.Oberösterreich 0.021511 0.114137 0.188 0.851
L1.Salzburg 0.080738 0.062996 1.282 0.200
L1.Steiermark 0.327058 0.080119 4.082 0.000
L1.Tirol 0.460909 0.055393 8.321 0.000
L1.Vorarlberg 0.144738 0.050816 2.848 0.004
L1.Wien -0.147974 0.103083 -1.435 0.151
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.201506 0.132891 1.516 0.129
L1.Burgenland 0.041391 0.065999 0.627 0.531
L1.Kärnten -0.076147 0.058216 -1.308 0.191
L1.Niederösterreich 0.106062 0.141833 0.748 0.455
L1.Oberösterreich 0.012474 0.136472 0.091 0.927
L1.Salzburg 0.195252 0.075323 2.592 0.010
L1.Steiermark 0.130972 0.095797 1.367 0.172
L1.Tirol 0.057043 0.066232 0.861 0.389
L1.Vorarlberg 0.107221 0.060760 1.765 0.078
L1.Wien 0.232074 0.123254 1.883 0.060
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.544085 0.072880 7.465 0.000
L1.Burgenland -0.013445 0.036195 -0.371 0.710
L1.Kärnten -0.015467 0.031927 -0.484 0.628
L1.Niederösterreich 0.094720 0.077784 1.218 0.223
L1.Oberösterreich 0.303722 0.074844 4.058 0.000
L1.Salzburg 0.013762 0.041309 0.333 0.739
L1.Steiermark -0.044583 0.052537 -0.849 0.396
L1.Tirol 0.080655 0.036323 2.220 0.026
L1.Vorarlberg 0.105077 0.033322 3.153 0.002
L1.Wien -0.063890 0.067595 -0.945 0.345
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.157859 0.097524 0.163823 0.219607 0.077913 0.083703 0.002204 0.153955
Kärnten 0.157859 1.000000 0.056548 0.209065 0.182665 -0.063243 0.173082 0.022256 0.304625
Niederösterreich 0.097524 0.056548 1.000000 0.246012 0.085821 0.320397 0.150148 0.020197 0.311187
Oberösterreich 0.163823 0.209065 0.246012 1.000000 0.305010 0.259945 0.096232 0.062759 0.137133
Salzburg 0.219607 0.182665 0.085821 0.305010 1.000000 0.152203 0.061378 0.090170 0.016347
Steiermark 0.077913 -0.063243 0.320397 0.259945 0.152203 1.000000 0.098832 0.099383 -0.100756
Tirol 0.083703 0.173082 0.150148 0.096232 0.061378 0.098832 1.000000 0.154249 0.152068
Vorarlberg 0.002204 0.022256 0.020197 0.062759 0.090170 0.099383 0.154249 1.000000 -0.007307
Wien 0.153955 0.304625 0.311187 0.137133 0.016347 -0.100756 0.152068 -0.007307 1.000000